package com.glsc.ngateway.common.base.repo.mysql.gateway.platform.webfield;

import com.glsc.ngateway.common.base.domain.mysql.gateway.platform.webfield.WebFieldItem;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import javax.validation.constraints.NotBlank;
import java.util.List;

/**
 * @author zhengyr
 * @date 2024/2/2-8:53
 * 每一个字段item配置表
 */
@Repository
public interface WebFieldItemRepository extends JpaRepository<WebFieldItem, Integer>, JpaSpecificationExecutor<WebFieldItem> {

    @Query(value="select * from t_gw_web_field_config h "+
            "where deleted =0 "+
            "and if ( :mainKey is not null, h.main_key = :mainKey, 1=1) " +
            "order by seq asc" +
            "", nativeQuery = true)
    List<WebFieldItem> findAllByMainKey(@NotBlank String mainKey);


    void deleteAllByMainKey(@NotBlank String mainKey);
}
